var app = getApp();
Page({
    data:{
        curPage : '/zofui_sales/pages/comment/comment',
        page : {
            isend : false,
            doing : false,
            doo : 'comm',
            pdata : {
                op : 'list',
                page : 1,
                type : 0,
                sortid : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        shoppage : {
            isend : false,
            doing : false,
            doo : 'shop_v1',
            pdata : {
                op : 'list',
                page : 1,
                type : 0,
                sortid : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        shoplist : [],
        goodsort : [],
        shopsort : [],
        showtype : 0,
        isIPX : app.globalData.isIPX,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        Time : app.globalData.Time,
    },
    onShow: function () {
        wx.hideTabBar();
    },
    onLoad:function(options){
        var self = this;

        self.setData({
            'page.pdata.status' : options.status ? options.status : 0,
            options : options,
            'page.pdata.zfid' : options.zfid ? options.zfid : '',
            //Menu : app.globalData.footer,
        });
		var shopid = options.shopid ? options.shopid : '';
        
        app.com.getLocation(self,function(loc){
            self.setData({
                'page.pdata.lng' : loc.longitude,
                'page.pdata.lat' : loc.latitude,
                'shoppage.pdata.lng' : loc.longitude,
                'shoppage.pdata.lat' : loc.latitude,
            });
            app.com.auth(function(user){
                app.com.getPage(self,self.data.page,20,function(res){
                    var data = res.data.data;

                    setTimeout(function(){
                        self.setData({
                        	inited : true,
                        	datalist : data.list,
                           	goodsort : data.goodsort,
                           	shopsort : data.shopsort,
                           	Pagetheme : data.params.style,
                           	params : data.params,
                           	sharedata : res.data.data.sharedata,
                        });
                        wx.stopPullDownRefresh();

                        wx.setNavigationBarTitle({
                          title:  res.data.data.params.title ? res.data.data.params.title : '好评',
                          //#FFD93F
                        });
                        var color = res.data.data.params.commbg ? res.data.data.params.commbg : '#ffd93f';
                        wx.setNavigationBarColor({
                            frontColor: '#ffffff',
                            backgroundColor: color,
                        });
                    },5)

                },false,function(res){
                    app.com.alert(res.data.message);
                });
				app.com.setBar(app,self,shopid);
            });
        })
       
        wx.setNavigationBarTitle({
          title:  '好评',
        });

    },
    onShareAppMessage : function(e){
        var self = this;
        if( e.target.dataset.id ){
            for (var i = 0; i < self.data.datalist.length; i++) {
                if( self.data.datalist[i].commid == e.target.dataset.id ){
                    return {
                        title: self.data.datalist[i].content,
                        path: '/zofui_sales/comment/info?id='+self.data.datalist[i].commid,
                        imageUrl : self.data.datalist[i].thumb,
                    }
                }
            }

        }else{
            return {
                title: self.data.sharedata.title,
                path: self.data.sharedata.path,
                imageUrl : self.data.sharedata.img,
            }
        }
    },
    onShareTimeline(){
        return {
            title: this.data.sharedata.title,
            query: this.data.sharedata.query,
            imageUrl : this.data.sharedata.img,
        }
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            isdown : true,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });
        wx.clearStorage();
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
    },
    commsort(e){
        var self = this;

        if( self.data.ising || ( e.currentTarget.dataset.id == self.data.page.pdata.sortid ) ) return false;
        self.data.ising = true;

        self.setData({
            datalist : [],
            'page.pdata.sortid' : e.currentTarget.dataset.id,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });

        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
            wx.pageScrollTo({
                scrollTop: 0
            });
        });

        self.data.ising = false;
    },
    shopsort(e){
        var self = this;

        if( self.data.ising || ( e.currentTarget.dataset.id == self.data.shoppage.pdata.sortid ) ) return false;
        self.data.ising = true;

        self.setData({
            shoplist : [],
            'shoppage.pdata.sortid' : e.currentTarget.dataset.id,
            'shoppage.pdata.page' : 1,
            'shoppage.isend' : false,
            'shoppage.waitf' : 0,
            'shoppage.nodataf' : 0
        });

        app.com.getPage(self,self.data.shoppage,20,function(res){
            self.setData({
                shoplist : res.data.data.list,
            });
            wx.pageScrollTo({
                scrollTop: 0
            });
        },'','','shoppage');

        self.data.ising = false;
    },
    showcomm(e){
        this.setData({
            showtype : e.currentTarget.dataset.type
        })
        if( this.data.shoppage.pdata.page <= 1 ){
            this.onReachBottom();
        }
    },
    onReachBottom : function(){
        var self = this;
        if( self.data.showtype == 0 ){
            app.com.getPage(self,self.data.page,20,function(res){
                self.setData({
                    datalist : self.data.datalist.concat(res.data.data.list)
                });
            });
        }else{
            app.com.getPage(self,self.data.shoppage,20,function(res){
                self.setData({
                    shoplist : self.data.shoplist.concat(res.data.data.list)
                });
            },'','','shoppage');
        }

    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },

})